﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VFCons
{
	public partial class BinWorkSetting : UserControl
	{
		public BinWorkSetting()
		{
			InitializeComponent();
		}

		private ushort _freq = 100;
		public ushort Freq
		{
			get { return _freq; }
			set { _freq = value;textBoxBoxFreq.Text = (_freq * 0.1F).ToString("F1"); }
		}

		private ushort _volt = 240;
		public ushort Volt
		{
			get { return _volt; }
			set { _volt = value;textBoxVolt.Text = (_volt * 0.1F).ToString("F1"); }
		}

		private int _timems = 500; 
		public int Times
		{
			get { return _timems; }
			set { _timems = value; textBoxBoxTime.Text = (_timems * 0.001F).ToString("F1"); }
		}

		private int _restafter = 100;
		public int RestAfter
		{
			get { return _restafter; }
			set { _restafter = value; textBoxStill.Text = (_restafter * 0.001F).ToString("F1"); }
		}

		private int _trycountbin = 2;
		public int TryCountBin
		{
			get { return _trycountbin; }
			set { _trycountbin = value;textBoxBinTry.Text = value.ToString(); }
		}

		private int _trycountshake = 2;
		public int TryCountShake
		{
			get { return _trycountshake; }
			set { _trycountbin = value; textBoxShakeCount.Text = value.ToString(); }
		}
		public bool UI2Data()
		{
			try
			{
				ushort freq = Convert.ToUInt16(Convert.ToSingle(textBoxBoxFreq.Text) * 10);
				ushort volt = Convert.ToUInt16(Convert.ToSingle(textBoxVolt.Text) * 10);
				int times = (int)Convert.ToUInt32(Convert.ToSingle(textBoxBoxTime.Text) * 1000);
				int ra = (int)Convert.ToUInt32(Convert.ToSingle(textBoxStill.Text) * 1000);

				int _bc = (int)Convert.ToUInt32(textBoxBinTry.Text);
				int _sc = (int)Convert.ToUInt32(textBoxShakeCount.Text);
				_freq = freq;
				_volt = volt;
				_timems = times;
				_restafter = ra;
				_trycountbin = _bc;
				_trycountshake = _sc;

				return true;
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, "BinWorkSetting.UI2Data" + Environment.NewLine + ex.Message, "ERROR");
				return false;
			}
		}
	}
}
